<template>
  <div class="page-style">
    <btn-area @exportExcel="exportExcel" @searchFun="searchFun" />
    <apply-tab :table-data="applyList" />
    <pagination :total="total" @pagination="currentPage" />
  </div>
</template>

<script>
import btnArea from './components/apply-link/btn-area'
import applyTab from './components/apply-link/apply-tab'
import pagination from '@/components/Pagination'
import { getApplyLinkListApi } from '@/api/agent'
import { getTime } from '@/utils/index'
export default {
  components: {
    btnArea,
    applyTab,
    pagination
  },
  data() {
    return {
      total: 0,
      brand_id: '',
      anent_id: '',
      status: '', // 0有效 1失效
      p: 1,
      num: 10,
      applyList: []
    }
  },
  created() {
    this.getApplyLinkList()
  },
  methods: {
    currentPage(val) {
      // console.log(val)
      this.p = val.page
      this.num = val.limit
    },
    exportExcel() {
      // console.log('exportExcel')
      import('@/vendor/Export2Excel').then(excel => {
        const theader = ['授权名', '手机号', '微信号', '品牌名称', '级别名称', '链接生成时间', '剩余时间（秒）', '状态', '打开次数']
        const data = []
        this.applyList.forEach(item => {
          data.push([item.anent_content.anent_name, item.anent_content.brand_phone, item.anent_content.anent_login_name, item.brand_content.brand_name, item.anent_brand_content.level_name.level_name, getTime(item.create_time), item.close_time - Date.parse(new Date()) / 1000 <= 0 ? '0' : item.close_time - Date.parse(new Date()) / 1000, item.status === '0' ? '正常' : '过时', item.see])
        })
        excel.export_json_to_excel({
          header: theader,
          filename: '申请链接列表',
          autoWidth: true,
          data
        })
      })
    },
    getApplyLinkList() {
      const data = {
        brand_id: this.brand_id,
        anent_id: this.anent_id,
        status: this.status,
        p: this.p,
        num: this.num
      }
      getApplyLinkListApi(data).then(res => {
        console.log(res)
        this.total = Number(res.count)
        this.applyList = res.list
      })
    },
    searchFun(val) {
      console.log(val)
      this.status = val.status
      this.getApplyLinkList()
    }
  }
}
</script>

<style scoped>

</style>
